/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.arrye.BayImg;

import javax.microedition.lcdui.*;

/**
 * @author Wilson.ARG
 */
public class ImageViewer extends Canvas {
    private Image _image;
    private int coordX, coordY;
    private int imageWidth, imageHeight;
    private int screenWidth, screenHeight;
    /**
     * constructor
     */
    public ImageViewer() {
        screenWidth = getWidth();
        screenHeight = getHeight();
    } 
    
    public void Initialize(Image img) {
        _image = img;
        imageWidth = _image.getWidth();
        imageHeight = _image.getHeight();
    }
    
    /**
     * paint
     */
    public void paint(Graphics g) {
        g.drawImage(_image, coordX, coordY, Graphics.LEFT | Graphics.TOP);
    }
    
    /**
     * Called when a key is pressed.
     */
    protected  void keyPressed(int keyCode) {
        int key = getGameAction(keyCode);
        switch (key) {
            case DOWN:
                if (coordY - screenHeight + imageHeight > 0)
                    coordY -= 10;
                break;
            case UP:
                if (coordY < 0)
                    coordY += 10;
                break;
            case RIGHT:
                if (coordX - screenWidth + imageWidth > 0)
                    coordX -= 10;
                break;
            case LEFT:
                if (coordX < 0)
                    coordX += 10;
                break;
        }
        repaint();
    }
}